package com.xisoft.bx.service.SqBill;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xisoft.bx.config.bill.*;
import com.xisoft.bx.entity.BillVO;
import com.xisoft.bx.entity.CostApplyDetailVO;
import com.xisoft.bx.entity.CostShareDetailVO;
import com.xisoft.bx.entity.SqBill.SqBillVO;
import com.xisoft.core.common.util.RestFul;
import com.xisoft.core.depend.excel.SerialNumberService;
import com.xisoft.core.product.action.SuperAction;
import com.xisoft.core.product.entity.ZSuperEntityVo;
import com.xisoft.core.product.entity.config.param.ConfigQuery;
import com.xisoft.core.product.entity.reference.Reference;
import com.xisoft.core.product.handle.HandlerConfigChain;
import com.xisoft.core.product.params.*;
import com.xisoft.core.product.queue.SourceQueue;
import com.xisoft.core.product.utils.PubConvert;
import com.xisoft.core.product.utils.PubResult;
import com.xisoft.core.tdata.common.TableDao;
import com.xisoft.security.CurrentUser;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author xzh
 * @Date 2022/9/6 11:20
 * @Description
 * @Version 1.0
 **/
@Service("BillAppService")
public class SqBillAppService extends SqBillServiceImpl {

    @Autowired
    private SerialNumberService serialNumberService;

    public PubResult businessBillConfig(JSONObject config) throws Exception {
        return ((SuperAction) AopContext.currentProxy()).billConfig(config);
    }

    public PubResult businessBillQuery(JSONObject config) throws Exception {
        return ((SuperAction) AopContext.currentProxy()).billQuery(config);
    }

    public PubResult businessBillSave(JSONObject config) throws Exception {
        return ((SuperAction) AopContext.currentProxy()).billSave(config);
    }

    public PubResult businessBillDelete(JSONObject config) throws Exception {
        return ((SuperAction) AopContext.currentProxy()).billDelete(config);
    }

    public PubResult businessBillUpdate(JSONObject config) throws Exception {
        return ((SuperAction) AopContext.currentProxy()).billUpdate(config);
    }

    public PubResult businessDataSourcesQuery(JSONObject config) throws Exception {
        return ((SuperAction) AopContext.currentProxy()).billDataSource(config);
    }


    /**
     * 加载配置
     *
     * @param handler
     * @throws Exception
     */
    @Override
    public void handler(HandlerConfigChain handler) throws Exception {
        handler.addHandler(new SQ01Form_XZH());//公务外出申请单
        handler.addHandler(new AppBxsqCostDetailList());//预算费用分摊明细
        handler.addHandler(new AppBxsqZxCostDetailList());//专项费用分摊明细
        handler.addHandler(new BxCostApplyEmpList());//人员信息
        handler.addHandler(new BxsqYSCostDetailList());//新申请单预算明细
        handler.addHandler(new CostDetailList());//申请单明细
        super.handler(handler);
    }

    /**
     * 初始化配置
     *
     * @param config
     * @throws Exception
     */
    @Override
    public void initConfig(Config config) throws Exception {
        super.initConfig(config);
    }

    /**
     * 获取配置
     *
     * @param config
     * @throws Exception
     */
    @Override
    public void config(Config config) throws Exception {
        super.config(config);
    }

    /**
     * 初始化查询
     *
     * @param query
     * @throws Exception
     */
    @Override
    public void initQuery(Query query) throws Exception {
        //1.session
        //2.前端传递的参数
        Map<String, Object> params = query.getParams();
        if (params == null) {
            params = new HashMap<>();
        }
        //3.系统默认参数
        CurrentUser currentUser = new CurrentUser();
        //4.所属组织
        String userCompanyID = CurrentUser.getUserCompanyID();
        params.put("userCompanyID", userCompanyID);
        //5.当前组织
        String userCurrenCompanyID = CurrentUser.getUserCurrenCompanyID();
        params.put("userCurrenCompanyID", userCurrenCompanyID);
        //6.用户信息
        JSONObject userInfo = CurrentUser.getUserInfo();
        params.put("userInfo", userInfo);
        //7.用户ID
        String userID = CurrentUser.getUserID();
        params.put("userID", userID);
        //8.用户名称
        String userName = CurrentUser.getUserName();
        params.put("userName", userName);
        //9.用户编码
        String userCode = CurrentUser.getUserCode();
        params.put("userCode", userCode);
        //10.人员信息
        String empID = CurrentUser.getEmpID();
        params.put("empID", empID);
        super.initQuery(query);
    }

    /**
     * 获取查询数据
     *
     * @param query
     * @throws Exception
     */
    @Override
    public void query(Query query) throws Exception {
        long l1 = System.currentTimeMillis();
        // 主表参数
        Map<String, Object> mainValMap = query.getMainParams();
        // 主数据
        Map<String, Object> bill = query.getMainData();
        String str = JSONObject.toJSONString(bill);
        SqBillVO sqBillVO = JSONObject.toJavaObject(JSON.parseObject(str), SqBillVO.class);

        // 单据类型主键
        // 当前单据用户
        String bbd_id = PubConvert.ToString(bill.get("bbd_id"));
        String user_id = PubConvert.ToString(bill.get("user_id"));

        //单据分摊类型
        String bbd_cost_type = getCostTypeByBBD(bbd_id);
        bill.put("bbd_cost_type", bbd_cost_type);
        //单据已提交是否允许修改附件

        long l2 = System.currentTimeMillis();
        String link_order_type = PubConvert.ToString(mainValMap.get("link_order_type"));
        String is_submit_editfile = getIsSubmitEditfile(link_order_type);
        bill.put("is_submit_editfile", is_submit_editfile);
        long l3 = System.currentTimeMillis();

        System.out.println("query单据已提交是否允许修改附件：" + (l3 - l3));


        //当前用户人员名称 ----
        //当前用户人员职称编码
        //当前用户人员职称编码

        long l4 = System.currentTimeMillis();
        Map<String, String> persionNameAndTeachMap = getPersionNameAndTeach(user_id);
        bill.put("ca_user", user_id);
        bill.put("ca_user_text", persionNameAndTeachMap.get("persion_name"));
        bill.put("persion_teach_title", persionNameAndTeachMap.get("persion_teach_title"));//
        bill.put("technical", persionNameAndTeachMap.get("persion_teach_title"));
        long l5 = System.currentTimeMillis();
        System.out.println("query用户职称：" + (l5 - l4));


        //当前用户人员职称名称
        long l6 = System.currentTimeMillis();
        String technical = getSysDataCodeTechnical(persionNameAndTeachMap.get("persion_teach_title"));
        bill.put("technical_text", technical);
        long l7 = System.currentTimeMillis();
        System.out.println("query用户人员职称名称：" + (l7 - l6));

        long l8 = System.currentTimeMillis();
        String area_id = PubConvert.ToString(bill.get("area"));
        bill.put("area_text", getAreaName(area_id));
        long l9 = System.currentTimeMillis();
        System.out.println("query地区：" + (l9 - l8));

        //同行人数量
        long l10 = System.currentTimeMillis();
        Map<String, String> partnerCount = queryPartnerCount(bbd_id);
        bill.put("partnerCount", partnerCount.get("num"));
        String companyID = CurrentUser.getUserCurrenCompanyID();
        Map<String, String> paramPropertyValue = queryValueByComAndCode(companyID);
        bill.putAll(paramPropertyValue);
        long l11 = System.currentTimeMillis();
        System.out.println("query同行人：" + (l11 - l10));

        //当前人员对应的用户
        long l12 = System.currentTimeMillis();
        Map<String, String> empInfo = getEmpInfo();
        bill.put("empInfo", empInfo);
        String emp_ids = getAgentIDListStr(empInfo.get("bhe_id"), user_id);
        bill.put("emp_ids", emp_ids);
        long l13 = System.currentTimeMillis();
        System.out.println("query对应用户：" + (l13 - l12));

        long ll2 = System.currentTimeMillis();

        System.out.println("query时间：" + (ll2 - l1));
        super.query(query);
    }

    @Override
    public void reference(Query query) throws Exception {
        long l1 = System.currentTimeMillis();
        ConfigQuery mainConfig = query.getConfigMap().get("main");
        Map<String, Object> mainMap = mainConfig.getValMap();
        //表单编码
        String formCode = PubConvert.ToString(mainMap.get("formCode"));
        // 主数据
        Map<String, Object> bill = query.getMainData();
        // 用户
        // 组织科室
        // 所有代理人员
        // 单据类型
        String user_id = PubConvert.ToString(bill.get("user_id"));
        String companyID = CurrentUser.getUserCurrenCompanyID();
        String emp_ids = PubConvert.ToString(bill.get("emp_ids"));
        String bbd_id = PubConvert.ToString(bill.get("bbd_id"));
        Map<String, Object> empInfo = PubConvert.beanToMap(bill.get("empInfo"));

        // 费用明细
        List<Map<String, String>> costDetail = queryCostDetailForSecect(companyID, bbd_id);
        bill.put("costDetail", costDetail);

        //代理人下拉列表
        List<Map<String, Object>> agentList = getAgentList(emp_ids);
        SourceQueue.put(new Reference().JSONSelect(formCode, "ca_user", agentList));

        new Reference().dicSelect("org_id", "YESORNO");
        //科室下拉框
        Map<String, List<Map<String, Object>>> orgsAll = getOrgsAll(emp_ids, companyID);
        List<Map<String, Object>> orgs = getOrgs(orgsAll, user_id, PubConvert.ToString(empInfo.get("bhe_id")));
        SourceQueue.put(new Reference().JSONSelect(formCode, "org_id", orgs));

        long l2 = System.currentTimeMillis();

        System.out.println("reference时间：" + (l2 - l1));
        super.reference(query);
    }


    /**
     * 保存前校验
     *
     * @param save
     * @throws Exception
     */
    @Override
    public void initSave(Save save) throws Exception {
        List<Map<String, List<? extends ZSuperEntityVo>>> dataVOs = save.getDataVOs();
        Map<String, List<? extends ZSuperEntityVo>> voMaps = dataVOs.get(0);
        //主表数据
        List<BillVO> billVOs = (List<BillVO>) voMaps.get("BillVO");
        BillVO billVO = billVOs != null && billVOs.size() > 0 ? billVOs.get(0) : new BillVO();
        //费用明细实体
        List<CostApplyDetailVO> costApplyDetailVO = (List<CostApplyDetailVO>) voMaps.get("CostApplyDetailVO");
        //分摊明细实体
        List<CostShareDetailVO> costShareDetailVO = (List<CostShareDetailVO>) voMaps.get("CostShareDetailVO");
        //校验主表数据
        CheckMain(billVO);
        //校验子表数据
        CheckDetail(costApplyDetailVO);

        billVO.setBb_code(getSerialNumber("BX_BILL_CODE"));

        //计算总金额 = 明细金额之和
        billVO.setApply_amount(SumAmount(costApplyDetailVO));
        //分摊方式
        String bbd_cost_type = getCostTypeByBBD(billVO.getBbd_id());

        //预算占用
        if ("CBMS".equals(bbd_cost_type)) {
            YSCheck(billVO, costShareDetailVO);
        }
        //专项占用
        if ("SPM".equals(bbd_cost_type)) {
            ZXCheck(billVO, costShareDetailVO);
        }
        super.initSave(save);
    }

    /**
     * 保存方法
     *
     * @param save
     * @throws Exception
     */
    @Override
    public void save(Save save) throws Exception {
        super.save(save);
    }

    /**
     * 更新前方法
     *
     * @param update
     * @throws Exception
     */
    @Override
    public void initUpdate(Update update) throws Exception {
        List<Map<String, List<? extends ZSuperEntityVo>>> dataVOs = update.getDataVOs();
        Map<String, List<? extends ZSuperEntityVo>> voMaps = dataVOs.get(0);
        //主表数据
        List<BillVO> billVOs = (List<BillVO>) voMaps.get("BillVO");
        BillVO billVO = billVOs != null && billVOs.size() > 0 ? billVOs.get(0) : new BillVO();
        //费用明细实体
        List<CostApplyDetailVO> costApplyDetailVO = (List<CostApplyDetailVO>) voMaps.get("CostApplyDetailVO");
        //分摊明细实体
        List<CostShareDetailVO> costShareDetailVO = (List<CostShareDetailVO>) voMaps.get("CostShareDetailVO");
        //校验主表数据
        CheckMain(billVO);
        //校验子表数据
        CheckDetail(costApplyDetailVO);
        //计算总金额 = 明细金额之和
        billVO.setApply_amount(SumAmount(costApplyDetailVO));
        //分摊方式
        String bbd_cost_type = getCostTypeByBBD(billVO.getBbd_id());

        //预算占用
        if ("CBMS".equals(bbd_cost_type)) {
            YSCheck(billVO, costShareDetailVO);
        }
        //专项占用
        if ("SPM".equals(bbd_cost_type)) {
            ZXCheck(billVO, costShareDetailVO);
        }
        super.initUpdate(update);
    }

    //主表数据校验
    public void CheckMain(BillVO billVO) throws Exception {
        if (billVO == null) {
            throw new Exception("单据不存在!");
        }
        String train_type = billVO.getTrain_type();
        if (StringUtils.isEmpty(train_type)) {
            //throw new Exception("请选择培训类型！");
        }
        String metting_type = billVO.getMetting_type();
        if (StringUtils.isEmpty(metting_type)) {
            //throw new Exception("请选择会议类型！");
        }
    }

    //校验费用明细
    public void CheckDetail(List<CostApplyDetailVO> costApplyDetailVO) throws Exception {
        if (CollectionUtils.isEmpty(costApplyDetailVO)) {
            throw new Exception("未填写明细不能保存!");
        }
    }

    //生成编码 ： 唯一
    public String getSerialNumber(String sn_code) throws Exception {
        Map<String, Object> valMap = new HashMap<>();
        valMap.put("sn_code", sn_code);

        JSONObject jsonObject = serialNumberService.getSerialNumber(sn_code, valMap);
        if (jsonObject == null) {
            throw new Exception("生成申请单编码失败，编号【" + sn_code + "】");
        }
        String status = jsonObject.getString("status");
        if (!"0".equals("status")) {
            throw new Exception(jsonObject.getString("message"));
        }
        String srialNumber = jsonObject.getJSONObject("result").getString("data");
        return srialNumber;
    }

    //计算金额
    public double SumAmount(List<CostApplyDetailVO> costApplyDetailVO) {
        double apply_amount = 0.00;
        for (CostApplyDetailVO vo : costApplyDetailVO) {
            apply_amount += vo.getAmount();
        }
        return apply_amount;
    }

    //预算校验
    public void YSCheck(BillVO billVO, List<CostShareDetailVO> costShareDetailVOs) throws Exception {
        if (1 == 1) {
            return;
        }
        List<Map<String, Object>> dataList = new ArrayList<>();
        for (CostShareDetailVO costShareDetailVO : costShareDetailVOs) {
            Map<String, Object> map = new HashMap<>();
            map.put("finalversion_id", costShareDetailVO.getFinalversion_id());
            map.put("bcsd_amount", costShareDetailVO.getBrcsd_amount());
            map.put("brcsd_amount", costShareDetailVO.getBrcsd_amount());
            map.put("pre_all_num", costShareDetailVO.getBrcsd_amount());
            map.put("bproject_balance", costShareDetailVO.getBproject_balance());
            map.put("bb_id", billVO.getBb_id());
            map.put("budget_id", costShareDetailVO.getBudget_id());
            map.put("cbfl_formbid", billVO.getBbd_id());
            map.put("receipt_num", costShareDetailVO.getBrcsd_amount());
            map.put("apply_psn", billVO.getUser_id());
            map.put("cbfd_id", "");
            map.put("cbfd_front", "");
            map.put("brcsd_id", "子表主键");//TODO
            dataList.add(map);
        }
        if (!CollectionUtils.isEmpty(dataList)) {
            Map<String, Object> map = new HashMap<>();
            map.put("method", "check");
            map.put("funSystem", "bx");
            map.put("org_id", CurrentUser.getUserCurrenCompanyID());
            map.put("zx_num", billVO.getBb_id());
            map.put("zx_code", billVO.getBb_code());
            map.put("cbfd_code", getCostTypeCodeByBBD(billVO.getBbd_id()));
            map.put("cbfd_source", "");
            map.put("applycode", "");
            map.put("applyid", "");
            map.put("zx_date", billVO.getEnter_date());
            map.put("cbfl_auditdate", billVO.getApproval_date());
            map.put("cbfl_period", "");
            map.put("is_apply", "");
            map.put("valList", dataList);
            String posting = RestFul.posting("http://127.0.0.1:32111", JSONObject.toJSONString(map));
            if (StringUtils.isEmpty(posting)) {
                JSONObject jsonObject = JSONObject.parseObject(posting);
                String status = jsonObject.getString("status");
                if ("-1".equals(status)) {
                    //预算反写
                    List<Map<String, Object>> valList = new ArrayList<>();
                    for (Map<String, Object> m : dataList) {
                        Map<String, Object> valMap = new HashMap<>();
                        valMap.put("brcsd_id", m.get("brcsd_id"));
                        valMap.put("is_over_budget", "1");
                        valList.add(valMap);
                    }
                    int i = tableDao.bUpdateById("bx", "BX_REFUND_COST_SHARE_DETAIL", valList);
                    if (i < 0) {
                        throw new Exception("是否超预算反写失败！");
                    }
                    if (i > 0) {
                        //预算超标逻辑
                        //强制逻辑
                        //提示逻辑
                    }
                }

            } else {
                throw new Exception("预算执行校验错误!");
            }

        }

    }

    //专项校验
    public void ZXCheck(BillVO billVO, List<CostShareDetailVO> costShareDetailVOs) throws Exception {
        if (1 == 1) {
            return;
        }
        List<Map<String, Object>> dataList = new ArrayList<>();
        for (CostShareDetailVO costShareDetailVO : costShareDetailVOs) {
            Map<String, Object> map = new HashMap<>();
            map.put("finalversion_id", costShareDetailVO.getFinalversion_id());
            map.put("bcsd_amount", costShareDetailVO.getBrcsd_amount());
            map.put("brcsd_amount", costShareDetailVO.getBrcsd_amount());
            map.put("pre_all_num", costShareDetailVO.getBrcsd_amount());
            map.put("bproject_balance", costShareDetailVO.getBproject_balance());
            map.put("bb_id", billVO.getBb_id());
            map.put("budget_id", costShareDetailVO.getBudget_id());
            map.put("cbfl_formbid", billVO.getBbd_id());
            map.put("receipt_num", costShareDetailVO.getBrcsd_amount());
            map.put("apply_psn", billVO.getUser_id());
            map.put("cbfd_id", "");
            map.put("cbfd_front", "");
            map.put("brcsd_id", "子表主键");//TODO
            dataList.add(map);
        }
        if (!CollectionUtils.isEmpty(dataList)) {
            Map<String, Object> map = new HashMap<>();
            map.put("method", "check");
            map.put("funSystem", "bx");
            map.put("org_id", CurrentUser.getUserCurrenCompanyID());
            map.put("zx_num", billVO.getBb_id());
            map.put("zx_code", billVO.getBb_code());
            map.put("cbfd_code", "business_type_code");//TODO
            map.put("cbfd_source", "");
            map.put("applycode", "");
            map.put("applyid", "");
            map.put("zx_date", billVO.getEnter_date());
            map.put("cbfl_auditdate", billVO.getApproval_date());
            map.put("cbfl_period", "");
            map.put("is_apply", "");
            map.put("valList", dataList);
            String posting = RestFul.posting("http://127.0.0.1:32111/WBbudgetControl/WBbudgetExcute", JSONObject.toJSONString(map));
            if (StringUtils.isEmpty(posting)) {
                JSONObject jsonObject = JSONObject.parseObject(posting);
                String status = jsonObject.getString("status");
                if ("-1".equals(status)) {
                    //预算反写
                    List<Map<String, Object>> valList = new ArrayList<>();
                    for (Map<String, Object> m : dataList) {
                        Map<String, Object> valMap = new HashMap<>();
                        valMap.put("brcsd_id", m.get("brcsd_id"));
                        valMap.put("is_over_budget", "1");
                        valList.add(valMap);
                    }
                    int i = tableDao.bUpdateById("bx", "BX_REFUND_COST_SHARE_DETAIL", valList);
                    if (i < 0) {
                        throw new Exception("是否超预算反写失败！");
                    }
                    if (i > 0) {
                        //预算超标逻辑
                        //强制逻辑
                        //提示逻辑
                    }
                }

            } else {
                throw new Exception("预算执行校验错误!");
            }

        }
    }

    /**
     * 更新后方法
     *
     * @param update
     * @throws Exception
     */
    @Override
    public void update(Update update) throws Exception {
        super.update(update);
    }

    @Override
    public void initDelete(Delete delete) throws Exception {
        List<Map<String, List<? extends ZSuperEntityVo>>> dataVOs = delete.getDataVOs();
        Map<String, List<? extends ZSuperEntityVo>> voMaps = dataVOs.get(0);
        //主表数据
        List<BillVO> billVOs = (List<BillVO>) voMaps.get("BillVO");
        BillVO billVO = billVOs != null && billVOs.size() > 0 ? billVOs.get(0) : new BillVO();
        //删除状态校验
        deleteStatusCheck(billVO);
        //分摊方式
        String bbd_cost_type = getCostTypeByBBD(billVO.getBbd_id());
        //预算占用
        if ("CBMS".equals(bbd_cost_type)) {
            ysSC(billVO);
        }
        //专项占用
        if ("SPM".equals(bbd_cost_type)) {
            zxSC(billVO);
        }
        Map<String, Object> valMap = new HashMap<>();
        valMap.put("delete_flag", "1");
        valMap.put("bb_id", billVO.getBb_id());

        tableDao.updateById("BX_BILL", valMap);

        super.initDelete(delete);
    }


    /**
     * 删除状态校验
     *
     * @throws Exception
     */
    public void deleteStatusCheck(BillVO billVO) throws Exception {
        String status = billVO.getStatus();
        if ("YTJ".equals(status)) {
            throw new Exception("已提交状态的单据不可删除！");
        }
        if ("SPZ".equals(status)) {
            throw new Exception("审批中状态的单据不可删除！");
        }
        if ("YSP".equals(status)) {
            throw new Exception("已审批状态的单据不可删除！");
        }
    }

    /**
     * @throws Exception
     */
    public void ysSC(BillVO billVO) throws Exception {
        if (1 == 1) {
            return;
        }
        String business_type_code = getCostTypeCodeByBBD(billVO.getBbd_id());
        List<Map<String, Object>> valList = getYSZXDataList(billVO, business_type_code);

        Map<String, Object> valMap = new HashMap<>();
        valMap.put("method", "delete");
        valMap.put("funSystem", "bx");
        valMap.put("org_id", CurrentUser.getUserCurrenCompanyID());
        valMap.put("zx_num", billVO.getBb_id());
        valMap.put("zx_code", billVO.getBb_code());
        valMap.put("cbfd_code", business_type_code);
        valMap.put("cbfd_source", "");
        valMap.put("applycode", "");
        valMap.put("applyid", "");
        valMap.put("zx_date", billVO.getEnter_date());
        valMap.put("cbfl_auditdate", billVO.getApproval_date());
        valMap.put("cbfl_period", "");
        valMap.put("is_apply", "");
        valMap.put("valList", valList);

        String posting = RestFul.posting("http://127.0.0.1:32111/WBbudgetControl/WBbudgetExcute", JSONObject.toJSONString(valMap));
        if (StringUtils.isEmpty(posting)) {
            JSONObject jsonObject = JSONObject.parseObject(posting);
            String status = jsonObject.getString("status");
            if (!"0".equals(status)) {
                throw new Exception(jsonObject.getString("message"));
            }
        } else {
            throw new Exception("预算执行校验错误!");
        }

    }

    /**
     * 获取预算分摊明细
     *
     * @param billVO
     * @param business_type_code
     * @return
     */
    public List<Map<String, Object>> getYSZXDataList(BillVO billVO, String business_type_code) {
        Map<String, Object> valMap = new HashMap<>();
        valMap.put("bb_id", billVO.getBb_id());
        valMap.put("bbd_cost_type", "CBMS");
        List<Map<String, Object>> detailList = (List<Map<String, Object>>) configDao.executeConfig("queryBcsdByBBIdAndCostType", valMap);
        List<Map<String, Object>> list = new ArrayList<>();
        if (!CollectionUtils.isEmpty(detailList)) {
            for (Map<String, Object> map : detailList) {
                Map<String, Object> m = new HashMap<>();
                m.put("budget_id", map.get("budget_id"));
                m.put("cbfl_formid", map.get("bb_id"));
                m.put("bcom_id", CurrentUser.getUserCurrenCompanyID());
                m.put("finalversion_id", map.get("finalversion_id"));
                m.put("cbfl_formbid", business_type_code);
                m.put("apply_psn", billVO.getUser_id());
                m.put("cbfd_id", "");
                m.put("pre_all_num", billVO.getApply_amount());
                m.put("cbfd_front", "");

                list.add(m);
            }
        }
        return list;
    }

    /**
     * @throws Exception
     */
    public void zxSC(BillVO billVO) throws Exception {
        if (1 == 1) {
            return;
        }
        String business_type_code = getCostTypeCodeByBBD(billVO.getBbd_id());
        List<Map<String, Object>> valList = getYSZXDataList(billVO, business_type_code);

        Map<String, Object> valMap = new HashMap<>();
        valMap.put("method", "delete");
        valMap.put("funSystem", "bx");
        valMap.put("org_id", CurrentUser.getUserCurrenCompanyID());
        valMap.put("zx_num", billVO.getBb_id());
        valMap.put("zx_code", billVO.getBb_code());
        valMap.put("cbfd_code", business_type_code);
        valMap.put("cbfd_source", "");
        valMap.put("applycode", "");
        valMap.put("applyid", "");
        valMap.put("zx_date", billVO.getEnter_date());
        valMap.put("cbfl_auditdate", billVO.getApproval_date());
        valMap.put("cbfl_period", "");
        valMap.put("is_apply", "");
        valMap.put("valList", valList);

        String posting = RestFul.posting("http://127.0.0.1:32111/WBbudgetControl/WBbudgetExcute", JSONObject.toJSONString(valMap));
        if (StringUtils.isEmpty(posting)) {
            JSONObject jsonObject = JSONObject.parseObject(posting);
            String status = jsonObject.getString("status");
            if (!"0".equals(status)) {
                throw new Exception(jsonObject.getString("message"));
            }
        } else {
            throw new Exception("预算执行校验错误!");
        }

    }

    @Override
    public void delete(Delete delete) throws Exception {
        super.delete(delete);
    }
}
